<?php
/**
 * Auction:AuthController.php
 * @author qqinxl
 * Tue Aug 28 17:00:58 GMT 2007
 * 
 * @category   Auction
 * @package  
 * @copyright  Copyright (c) qqinxl
 */

class Admin_AuthController extends ControllerAction_Abstract  {
	
	public function loginAction() {
		$form = new Form_Auth_Login ( );	
		$form->setAttrib('action',$this->_baseUrl.'/admin/auth/login');
		$options[ActionHelper_ActionLogin::OPTIONS_FORM] = $form;
		$options[ActionHelper_ActionLogin::OPTIONS_I18NMSG_TRANSLATEARRAY] = array('p'=>'username');
		$options[ActionHelper_ActionLogin::OPTIONS_MODULE_AUTH] = Module_Impl_Auth::getInstance();
		
		$this->_helper->actionLogin->setOptions($options);
		$this->_helper->actionLogin->process();		
	}
	
	public function registerAction(){
		$form = new Form_User_Register();	
		$form->setAttrib('action',$this->_baseUrl.'/admin/auth/register');
		$options[ActionHelper_ActionPost::OPTIONS_FORM] = $form;
		$options[ActionHelper_ActionPost::OPTIONS_I18NMSG_TRANSLATEARRAY] = array ('p' => 'username', 'email' => 'email' );
		$options[ActionHelper_ActionPost::OPTIONS_MODULE_SELECT] = Module_Impl_User_Select::getInstance();
		$options[ActionHelper_ActionPost::OPTIONS_MODULE_OPRATION] = Module_Impl_User_Opration::getInstance();
		
		$this->_helper->actionPost->setOptions($options);
		$this->_helper->actionPost->process ();
	}
	
	
	public function logoutAction() {		
		$_SESSION ['message'] = $this->_ ( $this->getRequest()->getControllerName().'.'.$this->getRequest()->getActionName().'.success' );		
		$authModule = Module_Impl_Auth::getInstance ();
		$authModule->clearSession (true);
		$this->view->loginSuccess = true;
		if ($this->getRequest ()->isXmlHttpRequest ()){
			$this->render ( 'message' );
		}else{
			$this->_redirect ($this->_pageInfo->getModule());
		}
	}
	public function langAction(){		
		$local = $this->getParam('local');
		if(empty($local)){
			$local = $this->_config->local->default;
		}
		$s = new Zend_Session_Namespace('local');
		$locale_session = $this->_config->local->session_name;
		$s->$locale_session = $local;
		$this->_redirect($this->_pageInfo->getModule());
	}	
}